package com.mc2.docapp.disabilityassessmenttool.wrapper_computation;

import com.mc2.docapp.disabilityassessmenttool.Amputation.Class_Amputation;
import com.mc2.docapp.disabilityassessmenttool.ConginitalDef.Class_Conginital_Deficiency_component;
import com.mc2.docapp.disabilityassessmenttool.LowerLimb.Class_lowerLimb_component;
import com.mc2.docapp.disabilityassessmenttool.NewPatient;
import com.mc2.docapp.disabilityassessmenttool.SpinalAffection.C_cerebral_palsy;
import com.mc2.docapp.disabilityassessmenttool.SpinalAffection.C_dwafism;
import com.mc2.docapp.disabilityassessmenttool.SpinalAffection.Class_spinal_affection;
import com.mc2.docapp.disabilityassessmenttool.UpperLimb.Class_UpperLimb_component;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class FinalComputationDTO {
    private Class_UpperLimb_component class_upperLimb_component;
    private Class_lowerLimb_component class_lowerLimb_component;
    private Class_Amputation amputation;
    private C_dwafism dwarfism;
    private Class_Conginital_Deficiency_component congenitalDeficiencies;
    private Class_spinal_affection class_spinal_affection;
    private C_cerebral_palsy c_cerebral_palsy;
    private double TotalDisability = 0;

    public double calTotalDisablity(FinalComputationDTO wrapper_all_comp) {
        double a = NewPatient.finalDto.getClass_upperLimb_component().getTotalUPLIMBCompLEFT();
        double b = NewPatient.finalDto.getClass_upperLimb_component().getTotalUPLIMBCompRight();
        double c = NewPatient.finalDto.getClass_lowerLimb_component().getTotalLLComponentLEFT();
        double d = NewPatient.finalDto.getClass_lowerLimb_component().getTotalLLComponentRIGHT();
        double e = NewPatient.finalDto.getClass_spinal_affection().getTotalSpinalDisability();
        double f = NewPatient.finalDto.getDwarfism().getDwarfismValue();
        double g = NewPatient.finalDto.getCongenitalDeficiencies().getCalculation();
        double h = NewPatient.finalDto.getC_cerebral_palsy().getCerebralPalsyValue();
        double i = NewPatient.finalDto.getAmputation().getTotalAmpDisability();

        double step1;
        double step2;
        double step3;
        double step4;
        double step5;
        double step6;
        double step7;
        double step8;

        step1 = calByFormula(a, b);
        step2 = calByFormula(step1, c);
        step3 = calByFormula(step2, d);
        step4 = calByFormula(step3, e);
        step5 = calByFormula(step4, f);
        step6 = calByFormula(step5, g);
        step7 = calByFormula(step6, h);
        step8 = calByFormula(step7, i);

        return step8;
    }

    private double calByFormula(double a, double b) {
        if (a < b) {
            a = a + b;
            b = a - b;
            a = a - b;
        }
        if(a > 90d) {
            return a;
        }
        double c = a + (((90 - a) * b) / 90.0);
        return c;
    }
}
